package com.yanqu.road.server.cmd.activity.liondance;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.logic.pb.CrossRankPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LionDanceProto;
import com.yanqu.road.pb.commonactivity.CommonActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_LION_DANCE_GET_GET_MY_SCORE_RANK, desc = "我的排名（最高积分）")
public class CrossLionDanceGetMyRankCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        long userId = packet.getPlayerId();
        LionDanceProto.LionDanceActivityRankListReqMsg reqMsg = LionDanceProto.LionDanceActivityRankListReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        CommonActivityProto.CommonActivityRankListRespMsg.Builder respMsg = CommonActivityProto.CommonActivityRankListRespMsg.newBuilder();
        respMsg.setMyRank(-1);
        int conditionType = reqMsg.getConditionType();
        CrossUserRank crossUserRank = CrossRankPb.parseCrossUserRank(activityId, reqMsg.getRank(), conditionType);
        ActivityRankMgr.changeActivityNewRank(reqMsg.getActivityId(), conditionType, crossUserRank);
        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityNewRankListModel(activityId, conditionType);
        if(rankListModel != null) {
            int myRank = rankListModel.getMyRank(userId, serverId);
            respMsg.setMyRank(myRank);
        }
        MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.S_LION_DANCE_GET_GET_MY_SCORE_RANK_FROM_CROSS, respMsg));
    }

    @Override
    public void sendData() {

    }
}
